package com.asia5b.a5mall.home.activity

import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.asia5b.a5bmall.resource.ActCons
import com.asia5b.a5mall.middleware.config.CountrysRepository
import com.asia5b.a5bmall.same.adapter.ChoiceCurrencyAdapter
import com.asia5b.a5mall.home.databinding.ActivityChoicecurrencyBinding
import com.asia5b.a5mall.middleware.base.SimpleActivity
import com.asia5b.a5mall.middleware.base.SimpleViewModel
import com.asia5b.a5mall.middleware.model.member.CurrencyModel
import com.asia5b.a5mall.middleware.utils.appCurrencySelect
import com.asia5b.a5mall.middleware.utils.dddLog
import com.asia5b.a5mall.middleware.utils.newDivider
import com.asia5b.a5mall.middleware.utils.resetMainActivity
import kotlinx.android.synthetic.main.activity_choicecurrency.*

/**
 * Created by zhangyuncai on 2019/11/16.
 * 币种选择
 */
@Route(path = ActCons.ChoiceCurrencyActivity)
class ChoiceCurrencyActivity : SimpleActivity<SimpleViewModel, ActivityChoicecurrencyBinding>() {
    override val viewModelClazz: Class<SimpleViewModel>
        get() = SimpleViewModel::class.java

    override fun getDataBinding(): ActivityChoicecurrencyBinding {
        return ActivityChoicecurrencyBinding.inflate(layoutInflater)
    }
    override var sIsDark = true
    private val mDatas = arrayListOf<CurrencyModel>()
    private val mAdapter by lazy {
        ChoiceCurrencyAdapter(mDatas)
    }


    override fun initView() {

        rv_choicecurrency.run {
            layoutManager = LinearLayoutManager(mActivity)!!
            adapter = mAdapter
            addItemDecoration(newDivider(mActivity))
        }

        CountrysRepository.anyCallback<ArrayList<CurrencyModel>>({ currency_list ->
            mDatas.clear()
            mDatas.addAll(currency_list)
            mAdapter.notifyDataSetChanged()
            var select_currency = CountrysRepository.getCurrencySelect()
            for (currencyModel in currency_list) {
                if (select_currency.country_id == currencyModel.country_id) {
                    dddLog("当前币种:${currencyModel.currency_name}")
                    break
                }
            }

        }, CountrysRepository.currency)

        mAdapter.setOnItemClickListener { adapter, view, position ->
            val bean = mAdapter.getItem(position)!!
            appCurrencySelect = bean.country_id
            resetMainActivity(mActivity)
            finish()
        }
    }

    override fun initEvent() {
    }

    override fun initData() {
    }

}